# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi


export LANG=C.UTF-8
export PROMPT_COMMAND="history -a"
export HISTTIMEFORMAT="`echo $SSH_CLIENT | awk '{print $1,$2}'` %F %T "

#USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
USER_IP=`echo $SSH_CLIENT|awk '{printf("%s_%s",$1,$2)}'`
LOCAL_IP=`ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut -c 6-`
HISTDIR=/usr/share/.sshrec
if [ -z $USER_IP ]
then
USER_IP=`hostname`
fi
if [ ! -d $HISTDIR ]
then
mkdir -p $HISTDIR
chmod 777 $HISTDIR
fi
if [ ! -d $HISTDIR/${LOGNAME} ]
then
mkdir -p $HISTDIR/${LOGNAME}
chmod 600 $HISTDIR/${LOGNAME}
fi
export HISTSIZE=40960
DT=`date +%Y%m%d`

export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}_${LOCAL_IP}.history.$DT"
chmod 750 $HISTDIR/${LOGNAME}/*.history* 2>/dev/null

##record
path="$HISTDIR/${LOGNAME}/${USER_IP}_${LOCAL_IP}.$DT.cast"
if [ ! -f $path ];then
    asciinema rec $path
else
    asciinema rec $path --append
fi

